package com.guiassysdesigners.dao.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Repository;

import com.guiassysdesigners.dao.SuggestionDao;
import com.guiassysdesigners.model.Suggestion;
import com.guiassysdesigners.model.User;
import com.guiassysdesigners.service.UserSecurityAdvice;

@Repository("suggestionDao")
public class SuggestionDaoHibernate extends GenericDaoHibernate<Suggestion, Long> implements SuggestionDao {

	public SuggestionDaoHibernate() {
		super(Suggestion.class);
	}

    /**
     * {@inheritDoc}
     */
    @SuppressWarnings("unchecked")
	public List<Suggestion> getListSuggestion() {
    	Query qry = getSession().createQuery("from Suggestion suggestion order by upper(suggestion.title)");
        return qry.list();
	}
    
    @Override
    public Suggestion save(Suggestion suggestion) {
        return this.saveSuggestion(suggestion);
    }

    /**
     * {@inheritDoc}
     */
	public Suggestion saveSuggestion(Suggestion suggestion) {

        if (log.isDebugEnabled()) {
            log.debug("suggestion's id: " + suggestion.getId());
        }
        
        getSession().saveOrUpdate(suggestion);
        getSession().flush();
        return suggestion;
	}

}
